package com.example.juc.controller;

import java.util.concurrent.TimeUnit;

/**
 * @author jl
 * @since 2021/9/25 23:15
 */
public class Lock8Demo {
    public static void main(String[] args) {
        Phone phoneA = new Phone();
        Phone phoneB = new Phone();
        new Thread(() -> phoneA.sendMail(), "A线程").start();
        new Thread(phoneB::sendSms, "B线程").start();
    }
}

class Phone {
    public static synchronized void sendMail() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("===>sendMail");
    }

    public synchronized void sendSms() {
        System.out.println("===>sendSms");
    }
}
